/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef JUKUFRAME_H_
#define JUKUFRAME_H_

#include "boardwindow.h"
#include "footprintlibrarynode.h"
#include "footprint.h"
#include "flistbox.h"
#include "project.h"
#include "netcomponenttable.h"
#include "nettable.h"
#include "componenttable.h"
#include "netlist.h"
#include "board.h"
#include <wx/wx.h>
#include <vector>
#include <wx/grid.h>

class JukuFrame: public wxFrame, BoardChangeHandler
{
	void SearchFootprints(wxString s);
	
	BoardScrolledWindow *m_boardwindow;
	// If you want to see the board from somewhere else, you can find it
	// in wxGetApp().m_project->m_board
	Board *m_board;
	Netlist *m_netlist;
	wxTextCtrl *m_zoomtextctrl;
	wxTextCtrl *m_fsearchtextctrl;
	std::vector<Footprint*> m_matching_footprints;
	FListBox *m_footprintlist;
	NetComponentTable *m_netcomponenttable;
	NetTable *m_nettable;
	ComponentTable *m_componenttable;
	wxGrid *m_netlcompgrid;
	wxGrid *m_netgrid;
	wxGrid *m_componentgrid;
	int m_netgrid_selected_row;
	wxCheckBox *m_hilight_selected_net_check;
	std::vector<wxAcceleratorEntry> m_accelerator_entries;
public:

    JukuFrame();
    ~JukuFrame();
	
    void OnMenuPythonCommand(wxCommandEvent &event);
    void OnMenuPythonCheck(wxCommandEvent &event);

	void RefreshBoard();

	void OnThrowNetlistComponentsOnBoard(wxCommandEvent &event);
	void OnRemoveComponentsNotOnNetlist(wxCommandEvent &event);

    void OnZoomInButton(wxCommandEvent &event);
    void OnZoomOutButton(wxCommandEvent &event);
    void OnZoomTextEnter(wxCommandEvent &event);
	
    void OnFSearchText(wxCommandEvent &event);
    void OnFSearchTextEnter(wxCommandEvent &event);
	void OnFlistBoxNumberInput(wxCommandEvent &event);
	void OnFListBoxSelect(wxCommandEvent &event);
	void OnFListBoxDClick(wxCommandEvent &event);

	void OnAddNetlCompToBoard(wxCommandEvent &event);
	void OnCheckNets(wxCommandEvent &event);
	void OnHilightSelectedNetCheck(wxCommandEvent &event);
	void OnNetGridLeftClick(wxGridEvent &event);
	void OnComponentGridLeftClick(wxGridEvent &event);

	//BoardChangeHandler virtual function
	void ContentsChanged();

	//must call with NULL before currently set board is deleted
	void SetBoard(Board *board);
	//must call with NULL before currently set netlist is deleted
	void SetNetlist(Netlist *netlist);

	void UpdateZoomString();
	void FocusFootprintSearch();
	void FocusFootprintList();
	Footprint* GetSelectedFootprint();

	void UpdateHilightedNet();
	void UpdateFootprintList();

	bool GetControlState(){ if(m_board) return m_boardwindow->GetControlState(); return false; }
	bool GetShiftState  (){ if(m_board) return m_boardwindow->GetShiftState  (); return false; }

	void AddAcceleratorEntry(wxAcceleratorEntry entry);
	void UpdateAcceleratorTable();
	
	void SetMouseMode(BoardWindowMouseMode newmode);
	
private:
	DECLARE_DYNAMIC_CLASS(JukuFrame)
    DECLARE_EVENT_TABLE()
};

enum
{
	ID_MENU_PYTHON_COMMAND_FIRST = 1,
	ID_MENU_PYTHON_COMMAND_LAST = 2000,
	ID_MENU_PYTHON_CHECK_FIRST,
	ID_MENU_PYTHON_CHECK_LAST = 3000,
	
	ID_ZoomInButton,
	ID_ZoomOutButton,
	ID_ZoomText,
	ID_FSearchText,
	ID_FListBox,

	ID_NetlCompGrid,
	ID_AddNetlCompToBoard,
	ID_NetGrid,
	ID_ComponentGrid,
	ID_CheckNets,
	ID_HilightSelectedNetCheck,
};

#endif

